From: Brion Vibber Date: Sat, 4 Nov 2006 18:00:57 +0000 (+0000) Subject: * (bug 7801) Add support for parser function hooks in parser tests X-Git-Tag: 1.31.0-rc.0~55286 X-Git-Url: http://git.cyclocoop.org/%7D%7Cconcat%7B?a=commitdiff_plain;h=6c9dba257d2f462e016e61e4ab3f1185044aef0b;p=lhc%2Fweb%2Fwiklou.git * (bug 7801) Add support for parser function hooks in parser tests patch by Steve Sanbeg: http://bugzilla.wikimedia.org/attachment.cgi?id=2628&action=view --- diff --git a/RELEASE-NOTES b/RELEASE-NOTES index f664bb1570..ffe476b38a 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -140,6 +140,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * (bug 7774) MATH: aded more amstex functions * (bug 1182) MATH: fixed inconsistent rendering of upper case Greek letters in TeX * Fix regression in streaming page dump generation +* (bug 7801) Add support for parser function hooks in parser tests == Languages updated == diff --git a/maintenance/parserTests.inc b/maintenance/parserTests.inc index b01190a9b1..c34ba20b1b 100644 --- a/maintenance/parserTests.inc +++ b/maintenance/parserTests.inc @@ -99,6 +99,7 @@ class ParserTest { } $this->hooks = array(); + $this->functionHooks = array(); } /** @@ -167,6 +168,20 @@ class ParserTest { $section = null; continue; } + if( $section == 'endfunctionhooks' ) { + if( !isset( $data['functionhooks'] ) ) { + wfDie( "'endfunctionhooks' without 'functionhooks' at line $n\n" ); + } + foreach( explode( "\n", $data['functionhooks'] ) as $line ) { + $line = trim( $line ); + if( $line ) { + $this->requireFunctionHook( $line ); + } + } + $data = array(); + $section = null; + continue; + } if( $section == 'end' ) { if( !isset( $data['test'] ) ) { wfDie( "'end' without 'test' at line $n\n" ); @@ -264,6 +279,9 @@ class ParserTest { foreach( $this->hooks as $tag => $callback ) { $parser->setHook( $tag, $callback ); } + foreach( $this->functionHooks as $tag => $callback ) { + $parser->setFunctionHook( $tag, $callback ); + } wfRunHooks( 'ParserTestParser', array( &$parser ) ); $title =& Title::makeTitle( NS_MAIN, $titleText ); @@ -729,6 +747,22 @@ class ParserTest { } } + + /** + * Steal a callback function from the primary parser, save it for + * application to our scary parser. If the hook is not installed, + * die a painful dead to warn the others. + * @param string $name + */ + private function requireFunctionHook( $name ) { + global $wgParser; + if( isset( $wgParser->mFunctionHooks[$name] ) ) { + $this->functionHooks[$name] = $wgParser->mFunctionHooks[$name]; + } else { + wfDie( "This test suite requires the '$name' function hook extension.\n" ); + } + } + /* * Run the "tidy" command on text if the $wgUseTidy * global is true